<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /*
        要向服务器发送数据，使用 send()方法并 传入一个字符串、ArrayBuffer 或 Blob，
     */
    let socket = new WebSocket("ws://www.example.com/server.php");
    let stringData = "Hello world!";
    let arrayBufferData = Uint8Array.from(['f', 'o', 'o']);
    let blobData = new Blob(['f', 'o', 'o']);
    socket.send(stringData);
    socket.send(arrayBufferData.buffer);
    socket.send(blobData);
    
    
    /*
        服务器端会收到
        socket.onmessage = function(event) { 
        let data = event.data;
        // 对数据执行某些操作
        };
     */
</script>
</body>
</html>